#
# Copyright (C) 2013 rdrrlabs gmail com,
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
#
# Usage:
# source this from a script that defines a function wrap_py27_exec()
#

. ./_set_go_path.sh

if [[ $(uname -o) == "Cygwin" ]]; then
    wrap_py27_exec
else
    # Linux
    RR_PY27_DEACTIVATE=""

    if [[ $(python --version 2>&1 | cut -d " " -f 2) =~ "2.6" ]]; then
        echo "[PYTHON] 2.6 detected"
        ENV27=~/env-python27
        if [[ ! -d $ENV27 ]]; then
            echo "[PYTHON] creating $ENV27"
            mkdir $ENV27
            virtualenv --no-site-packages --python=python2.7 $ENV27
        fi
        source ~/env-python27/bin/activate
        echo "[PYTHON] Activating " $(python --version)
        RR_PY27_DEACTIVATE="1"
    fi

    echo "[EXEC] Starting exec"
    wrap_py27_exec "$P"

    if [[ -n $RR_PY27_DEACTIVATE ]]; then
        echo "[PYTHON] Deactivating " $(python --version)
        deactivate
    fi
fi

